package com.incross.dawin.http.parser;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;

import com.incross.dawin.util.CommonUtils;

import android.util.Log;

public class MediaFileInfoParser {
	
	private String mMediaFileUrl;
	private String mMediaDelivery;
	private String mMediaType;
	private String mThumbnailUrl;
	private int mMediaBitrate;
	private int mMediaWidth;
	private int mMediaHeight;
	
	public MediaFileInfoParser(NodeList list) {
		NodeList child = null;
		for(int i = 0; i < list.getLength(); i++) {
			if(list.item(i) != null) {
				child = list.item(i).getChildNodes();
				break;
			}
		}
		
		for(int i = 0; i < child.getLength(); i++) {
			if(child.item(i).getFirstChild() != null) {
				if(child.item(i).getNodeName().equals("MediaFile")) {
					mMediaFileUrl = child.item(i).getFirstChild().getNodeValue();
					
					NamedNodeMap attributes = child.item(i).getAttributes();
					for(int j = 0; j < attributes.getLength(); j++) {
						String attrName = attributes.item(j).getNodeName();
						String attrValue = attributes.item(j).getNodeValue();
						
						if(attrName.equals("delivery")) {
							mMediaDelivery = attrValue;
						} else if(attrName.equals("type")) {
							mMediaType = attrValue;
						} else if(attrName.equals("bitrate")) {
							mMediaBitrate = (CommonUtils.isNumber(attrValue)? Integer.parseInt(attrValue): -1);
						} else if(attrName.equals("width")) {
							mMediaWidth = (CommonUtils.isNumber(attrValue)? Integer.parseInt(attrValue): -1);
						} else if(attrName.equals("height")) {
							mMediaHeight = (CommonUtils.isNumber(attrValue)? Integer.parseInt(attrValue): -1);
						} else if(attrName.equals("thumb")) {
							mThumbnailUrl = attrValue;
						}
					}
					break;
				}
			}
		}
		
		
		
		
		
	}
	
	public String getMediaFileUrl() {
		return mMediaFileUrl;
	}
	
	public String getMediaDelivery() {
		return mMediaDelivery;
	}
	
	public String getMediaType() {
		return mMediaType;
	}
	
	public int getMediaBitrate() {
		return mMediaBitrate;
	}
	
	public int getMediaWidth() {
		return mMediaWidth;
	}
	
	public int getMediaHeight() {
		return mMediaHeight;
	}
	
	public String getMediaThumbnailUrl() {
		return mThumbnailUrl;
	}
	
	

}
